package net.lab1024.sa.admin.module.business.summary.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.summary.dao.SummaryItemsDao;
import net.lab1024.sa.admin.module.business.summary.domain.entity.SummaryItemsEntity;
import net.lab1024.sa.admin.module.business.summary.domain.form.SummaryItemsAddForm;
import net.lab1024.sa.admin.module.business.summary.domain.form.SummaryItemsQueryForm;
import net.lab1024.sa.admin.module.business.summary.domain.form.SummaryItemsUpdateForm;
import net.lab1024.sa.admin.module.business.summary.domain.vo.SummaryItemsVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * 报价单汇总明细 Service
 *
 * @Author zzx
 * @Date 2025-08-30 15:52:51
 * @Copyright zzx
 */

@Service
public class SummaryItemsService {

    @Resource
    private SummaryItemsDao summaryItemsDao;

    /**
     * 分页查询
     */
    public PageResult<SummaryItemsVO> queryPage(SummaryItemsQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<SummaryItemsVO> list = summaryItemsDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(SummaryItemsAddForm addForm) {
        SummaryItemsEntity summaryItemsEntity = SmartBeanUtil.copy(addForm, SummaryItemsEntity.class);
        summaryItemsDao.insert(summaryItemsEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(SummaryItemsUpdateForm updateForm) {
        SummaryItemsEntity summaryItemsEntity = SmartBeanUtil.copy(updateForm, SummaryItemsEntity.class);
        summaryItemsDao.updateById(summaryItemsEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        summaryItemsDao.batchUpdateDeleted(idList, true);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long summaryItemId) {
        if (null == summaryItemId){
            return ResponseDTO.ok();
        }

        summaryItemsDao.updateDeleted(summaryItemId, true);
        return ResponseDTO.ok();
    }
}
